<?php

namespace app\admin\controller;

use app\common\business\UserAssociation;
use app\common\business\UserInfo;
use app\common\lib\Param;
use app\common\lib\Show;
use think\response\Json;

class WxUser extends AdminBase
{
    /**
     * 管理后台列表
     * @return Json
     */
    public function list(): Json
    {
        list($name, $page,$limit,$sex) = Param::getMore([
            ['name', ''],
            ['page', 0],
            ['limit', 0],
            ['sex',''],
        ], $this->request, true);

        $userBis = new \app\common\business\User();

        try {
            $result=$userBis->getTableList($page,$limit,$name,$sex);
        }catch (\Exception $e){
            return Show::error([], $e->getMessage(), $e->getCode());
        }

        if (!empty($result['list'])) $result['list'] = $userBis->getListWithUserInfo($result['list']);
        return Show::success($result);
    }

    /**
     * 根据用户ID获取用户信息
     * @return Json
     */
    public function info(): Json
    {
        $id=$this->request->get('id');
        if(empty($id)){
            return Show::error([],'参数错误');
        }
        try {
            $result=(new UserInfo())->getNormalInfoByField('user_id',$id);
        }catch (\Exception $e){
            return Show::error([], $e->getMessage(), $e->getCode());
        }
        return Show::success($result);
    }

    /**
     * 审核房屋
     * @return Json
     */
    public function audit(): Json
    {
        list($userId, $check_status) = Param::postMore([
            ['user_id',null],
            ['check_status',null],
        ], $this->request, true);

        if(empty($userId)||empty($check_status)||!in_array($check_status,[2,3])){
            return Show::error([], '参数错误');
        }
        try {
            $result = (new UserInfo())->audit($userId,$check_status);
        } catch (\Exception $e) {
            return Show::error([], $e->getMessage(), $e->getCode());
        }
        if ($result) {
            return Show::success([], "审核成功");
        }
        return Show::error([], '审核失败');
    }
}
